package com.wiwf.model.manage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.gitee.fastmybatis.core.PageInfo;
import com.gitee.fastmybatis.core.mapper.CrudMapper;
import com.gitee.fastmybatis.core.query.Query;

public abstract class CURDController<E, I> {

    @Autowired
    public CrudMapper<E, I> crudMapper;
	
	@RequestMapping("/list")
	public PageInfo<E> list(@RequestParam(name = "page",defaultValue = "1")Integer page, @RequestParam(name = "limit",defaultValue = "1")Integer size){
		return crudMapper.page(new Query().page(page, size));
	}
	
	@RequestMapping("get")
	public E get(I id) {
		return crudMapper.getById(id);
	}
	
	@RequestMapping("delete")
	public int delete(I id){
		return crudMapper.deleteById(id);
	}
	
	@RequestMapping("save")
	public int save(E obj){
		return crudMapper.save(obj);
	}
	
	@RequestMapping("update")
	public int update(E obj){
		return crudMapper.updateIgnoreNull(obj);
	}
	
}